﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SharpCmd.Data
{
    class FileFiltersStackManager
    {
        const int MAX_COUNT = 2;
        public List<string> searches;
        const string FILE_NAME = "FileFiltersStackManager.dat";

        public FileFiltersStackManager()
        {
            Load();
        }

        public void Load()
        {
            searches = Configuration.DeserializeItem<List<string>>(GetFilePath());
            if (searches == null)
                searches = new List<string>();
        }

        public void Save()
        {
            Configuration.SerializeType(searches, GetFilePath());
        }

        private string GetFilePath()
        {
            return Path.Combine(Configuration.GetDirectory(), FILE_NAME);
        }

        public void Push(string s)
        {
            if (searches.Contains(s))
                searches.Remove(s);
            searches.Insert(0,s);
            //trim to MAX_COUNT
            while(searches.Count > MAX_COUNT)
                searches.RemoveAt(MAX_COUNT);
        }
    }
}
